{inc:header.htm}
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>{lang:search}</legend>
			<div>
				<form class="layui-form layui-form-pane">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">{lang:links_name}</label>
							<div class="layui-input-inline">
								<input placeholder="{lang:links_name}" autocomplete="off" type="text" class="layui-input" name="keyword" />
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> {lang:search}</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>
		<script type="text/html" id="toolbar">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add">{lang:add}</button>
				<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">{lang:batch_delete}</button>
			</div>
		</script>
		<table class="layui-hide" id="data-table" lay-filter="data-table-filter"></table>

		<script type="text/html" id="currentTableBar">
			<div class="layui-btn-group">
				<a class="layui-btn layui-btn-xs" lay-event="edit">{lang:edit}</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">{lang:delete}</a>
			</div>
		</script>
	</div>
</div>

<script type="text/javascript">
	layui.use(['form','layer', 'table', 'miniTab'], function () {
		var layer = layui.layer, form = layui.form, table = layui.table, miniTab = layui.miniTab;

		table.render({
			elem: '#data-table',
			url: 'index.php?links-get_list-',
			height: 'full-145',
			toolbar: '#toolbar',
			defaultToolbar: ['filter', 'exports', 'print'],
			cellMinWidth: 50,
			cols: [[
				{type: "checkbox", width: 50, fixed: 'left'},
				{field: 'name', minwidth: 120, title: '{lang:links_name}', edit: 'text'},
				{field: 'url', minwidth: 120, title: '{lang:links}', edit: 'text'},
				{field: 'orderby', width: 100, title: '{lang:orderby}', edit: 'number', align: "center"},
				{title: '{lang:opt}', width: 105, toolbar: '#currentTableBar', align: "center"}
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 15,
			page: true
		});
		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			//执行搜索重载
			table.reload('data-table', {
				page: {
					curr: 1
				}
				, where: {
					keyword: data.field.keyword
				}
			}, 'data');

			return false;
		});
		/**
		 * toolbar监听事件 table列表 头部的操作
		 */
		table.on('toolbar(data-table-filter)', function (obj) {
			if (obj.event === 'delete') {  // 监听删除操作
				var checkStatus = table.checkStatus('data-table')
						, data = checkStatus.data;
				var len = data.length;
				if(len == 0){
					layer.msg('{lang:select_data}',{icon:5});
					return false;
				}else{
					layer.confirm('{lang:delete_confirm}', function () {
						var id_arr = [];
						for (var i in data) {
							id_arr[i] = data[i]['id'];
						}
						adminAjax.postd("index.php?links-batch_del-ajax-1", {"id_arr": id_arr});
					});
				}
			}else if (obj.event === 'add') {
				miniTab.openNewTabByIframe({
					href:"index.php?links-add",
					title:"{lang:add_f_links}",
				});
			}
		});
		//监听单元格编辑
		table.on('edit(data-table-filter)', function(obj){
			var value = obj.value //得到修改后的值
					,data = obj.data //得到所在行所有键值
					,field = obj.field; //得到字段
			adminAjax.postd("index.php?links-set-ajax-1", {"id":data.id, "field":field, "value":value});
		});
		//监听每一行的操作
		table.on('tool(data-table-filter)', function (obj) {
			var data = obj.data;

			if (obj.event === 'delete') {
				layer.confirm('{lang:delete_confirm}', function () {
					adminAjax.postd("index.php?links-del-ajax-1", {"id":data.id});
				});
			}else if (obj.event === 'edit') {
				miniTab.openNewTabByIframe({
					href:"index.php?links-edit-id-"+data.id,
					title:"{lang:edit_f_links}",
				});
			}
		});
	});
</script>
</body>
</html>
